package com.wwy.monitor.common;

import org.slf4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ControllerExceptionHandler {

    private final Logger ERROR_LOGGER = BizLogFactory.getLogger(LoggerEnum.ERROR_LOGGER);

    @ExceptionHandler(value = {MessageException.class})
    @ResponseBody
    public ServiceResponse handle(MessageException messageException) {
        ERROR_LOGGER.error(messageException.getMessage(), messageException);
        return ServiceResponse.fail(0, messageException.getMessage());
    }

    @ExceptionHandler(value = {Exception.class})
    @ResponseBody
    public ServiceResponse handle(Exception exception) {
        ERROR_LOGGER.error(exception.getMessage(), exception);
        return ServiceResponse.fail(0, "服务处理异常");
    }

}
